<template>
  <div class="app-container">
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="专利名称" prop="zlName">
        <el-input size="mini"
                  v-model="queryParams.zlName"
                  placeholder="请输入专利名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请年度" prop="sqNd">
        <el-select size="mini" v-model="queryParams.sqNd" placeholder="请选择申请年度" clearable>
          <el-option
            v-for="dict in dict.type.year"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="流程状态:" prop="processStatus">
        <el-select v-model="queryParams.processStatus" placeholder="请选择流程状态" clearable size="mini">
          <el-option
            v-for="dict in dict.type.zl_lczt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="专利类型" prop="zlLx">
        <el-select size="mini" v-model="queryParams.zlLx" placeholder="请选择专利类型" clearable>
          <el-option
            v-for="dict in dict.type.zlsbnn_zllx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属领域" prop="ssLy">
        <el-select size="mini" v-model="queryParams.ssLy" placeholder="请选择所属领域" clearable>
          <el-option
            v-for="dict in dict.type.kylx_ssly"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="依托工程" prop="ytGc">
        <el-input size="mini"
                  v-model="queryParams.ytGc"
                  placeholder="请输入依托工程"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专利发明人" prop="zlFmr">
        <el-input size="mini"
                  v-model="queryParams.zlFmr"
                  placeholder="请输入专利发明人"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申报单位" prop="sbDw">
        <el-input size="mini"
                  v-model="queryParams.sbDw"
                  placeholder="请输入申报单位"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 顶部按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zlsb:zlsb:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="zlsbList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" width="50"/>
      <el-table-column label="申请年度" align="center" prop="sqNd" width="90" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.year" :value="scope.row.sqNd"/>
        </template>
      </el-table-column>
      <el-table-column label="专利名称" align="center" prop="zlName" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link type="primary">{{ scope.row.zlName }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="依托工程" align="center" prop="ytGc" show-overflow-tooltip/>
      <el-table-column label="实施日期" align="center" prop="ssRq" width="100" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ssRq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="专利类型" align="center" prop="zlLx" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zlsbnn_zllx" :value="scope.row.zlLx"/>
        </template>
      </el-table-column>
      <el-table-column label="所属领域" align="center" prop="ssLy" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.kylx_ssly" :value="scope.row.ssLy"/>
        </template>
      </el-table-column>
      <el-table-column label="申报单位" align="center" prop="sbDw" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xmgl_lxwj_pzdw" :value="scope.row.sbDw"/>
        </template>
      </el-table-column>
      <el-table-column label="第一发明人" align="center" prop="dyFmr" show-overflow-tooltip/>
      <el-table-column label="其他发明人" align="center" prop="qtFmr" show-overflow-tooltip/>
      <el-table-column label="申报日期" align="center" prop="sbTime" width="100" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sbTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务机构" align="center" prop="qqFwJg" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zlsb_qqfwjg" :value="scope.row.qqFwJg"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="processStatus" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zl_lczt" :value="scope.row.processStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="专利号" align="center" prop="sqZlh" show-overflow-tooltip/>
      <el-table-column label="申请日期" align="center" prop="sqSqTime" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sqSqTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="授权日期" align="center" prop="sqTime" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sqTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleJinDu(scope.row)"
            v-if="scope.row.processStatus !== 1"
          >查询进度
          </el-button>
          <el-link type="danger" disabled v-else>{{ '未提交审批' }}</el-link>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查询进度 -->
    <Jindu ref="picture"/>

    <!-- 专利申报详情 -->
    <ZlSbXq ref="zlSbXq"/>

  </div>
</template>

<script>
import {
  addZlsb,
  delZlFj,
  delZlsb,
  getZlsb,
  getZlSbId,
  insertZlsbFjByZlsbId,
  listZlsb, selectZlList,
  selectZlsbFjList,
  updateZlsb
} from "@/api/zscq/zlsb/zlsb";
import ImagePreviewBase64 from "@/components/ImagePreviewBase64";
import Jindu from "@/views/components/liuChengState/jindu";
import ZlSbXq from "@/views/zscq/zlgl/zlsb/components/ZlSbXq";

export default {
  name: "zlly", //专利领域
  components: {ZlSbXq, Jindu, ImagePreviewBase64},
  dicts: ['xmgl_lxwj_pzdw', 'zlsb_qqfwjg', 'year', 'zlsbnn_zllx', 'kylx_ssly', 'zl_lczt'],
  data() {
    return {
      selectedRow: null, // 保存当前选中的行
      loadingFj: false,
      number: 0,
      uploadList: [],
      fileType: ["doc", "xls", "ppt", "txt", "pdf", "docx", "zip"],
      getZlSbId: null, //从后端获取的专利申报主键ID (UUID)
      activeName: 'jbzl', //初始打开的标签页
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedZlglZlsbFj: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专利申报表格数据
      zlsbList: [],
      // 专利申报附件表格数据
      zlglZlsbFjList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zlName: null,
        sqNd: null,
        zlLx: null,
        ssLy: this.$route.query.ssLy,
        ytGc: null,
        kyXm: null,
        xmsbId: null,
        userId: null,
        deptId: null,
        processStatus: null,
        zlFmr: null,
        sbDw: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    resSubmit(ids) {
      this.form.kjryId = ids
    },
    // 查询详情信息
    handleButtonClick(row) {
      this.$refs.zlSbXq.handleOpen(row);
    },
    //查询进度
    handleJinDu(row) {
      this.$refs.picture.handleOpen(row);
    },
    //点击行内任意地方选中行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    /** 查询专利申报列表 */
    getList() {
      this.loading = true;
      selectZlList(this.queryParams).then(response => {
        this.zlsbList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        zlsbId: this.getZlSbId,
        zlName: null,
        sqNd: new Date().getFullYear(),
        zlLx: null,
        sbTime: this.getCurrentDate(),
        ssLy: null,
        ytGc: null,
        ssRq: null,
        sfzHm: null,
        dyFmr: null,
        qtFmr: null,
        kjryId: null,
        sbDw: null,
        zlqR: null,
        lxPhone: null,
        lxr: null,
        qqFwJg: null,
        bz: null,
        kyXm: null,
        xmsbId: null,
        sqSqTime: null,
        sqDgName: null,
        sqTime: null,
        sqZlh: null,
        idWhere: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        userId: null,
        deptId: null
      };
      this.zlglZlsbFjList = [];
      this.resetForm("formDialog");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      let ids = selection.map(item => item.zlsbId)
      if (ids.length === 1) {
        this.ids = ids[0]
      } else {
        this.ids = ids
      }
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 复选框选中数据 */
    handleZlglZlsbFjSelectionChange(selection) {
      this.checkedZlglZlsbFj = selection.map(item => item.fjId)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zlsb/zlsb/export', {
        ...this.queryParams
      }, `zlsb_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>

<style scoped>
.image-preview-wrapper {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中，如果需要的话 */
}
</style>
